package cn.gjxblog.inteceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConf extends WebMvcConfigurerAdapter {

  @Bean
  public TokenInterceptor getTokenInterceptor(){
      TokenInterceptor authInterceptor = new TokenInterceptor();
      return authInterceptor;
  }

  @Bean
  public LoginInterceptor getLoginInterceptor(){
      return  new LoginInterceptor();
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(getTokenInterceptor()).excludePathPatterns("/static").addPathPatterns("/**");
    registry
        .addInterceptor(getLoginInterceptor())
         .addPathPatterns("/house/toAdd")
        .addPathPatterns("/accounts/profile").addPathPatterns("/accounts/profileSubmit")
        .addPathPatterns("/house/bookmark").addPathPatterns("/house/del")
        .addPathPatterns("/house/ownlist").addPathPatterns("/house/add")
        .addPathPatterns("/house/toAdd").addPathPatterns("/agency/agentMsg")
        .addPathPatterns("/comment/leaveComment").addPathPatterns("/comment/leaveBlogComment");
    super.addInterceptors(registry);
  }

}
